$(function() {

    $('#side-menu').metisMenu();

    var url = window.location;
    var element = $('ul.nav a').filter(function() {
        return this.href == url || url.href.indexOf(this.href) == 0;
    }).addClass('active').parent().parent().addClass('in').parent();
    if (element.is('li')) {
        element.addClass('active');
    }else{
    	var element2 = $('ul.nav a').filter(function() {
    		return this.href == url && this.href.length > 0;
    	}).addClass('active').parent().addClass('active');
    }
});

//删除标签
function del_tag(obj)
{
    $(obj).parent().remove();
}

function changeResumeStatus(id,url,token,status)
{
	$.ajax({
		'url':url,
		'type':'POST',
		'data':'status='+status+'&_token='+token,
		error: function(data) {
			var response = data.responseJSON;
			$.each(response,function(k,v){
				errors +="<div>"+v+"</div>";
			})
			layer.open({title:'错误提示',content:errors});
        },
        success: function(data){
        	if(data.status == 'success'){
        		var spancalss = $(id).find('span').attr('class');
        		var html ='<span class="'+spancalss+' height-auto"></span>'
                    	+'<span class="padd-l-5">...</span>';
        		$(id).parent().parent().parent().find("#dropdownMenu1").html(html);
        	}
        },
	})
}
function changeResumeStatus2(url,token,status)
{
	$.ajax({
		'url':url,
		'type':'POST',
		'data':'status='+status+'&_token='+token,
		error: function(data) {
			var response = data.responseJSON;
			$.each(response,function(k,v){
				errors +="<div>"+v+"</div>";
			})
			layer.open({title:'错误提示',content:errors});
        },
        success: function(data){
        	if(data.status == 'success'){
        		window.location.reload();
        	}
        },
	})
}

/**
 * 删除
 * @param url 删除路径
 * @param id 文章id
 * @param token 
 */
function delete_one(url,id,token){
    layer.confirm('确认删除',{title:'确定要删除吗?'},function(result){
            if(result) {
                $.ajax({
                    'url':url,
                    'type':'DELETE',
                    'data':'_token='+token,
                    success: function(data){
                        if(data.status == 'success'){
                            layer.open({title:'提示',content:data.msg});
                            $("#news_"+id).remove();
                        }else{
                            layer.open({title:'提示',content:data.msg});
                        }

                    },
                });
            }else{
                layer.open({title:'提示',content:'删除操作已取消'});
            }
    });
}

function checkCompany(url,id){
	$.ajax({
		'url':url,
		'type':'GET',
		'error':function(data){
			$("#"+id).html('网络异常！');
		},
		success:function(data){
			if(data.status == 'success'){
				$("#"+id).html(data.msg);
				$("#"+id).css('color','green');
			}else{
				$("#"+id).html(data.msg);
				$("#"+id).css('color','red');
			}
		}
	});
}
/**
 * 职位地区，根据父分类获取子分类
 */
function childAreas(pid,uri,id){
	$.ajax({
		'url':'/'+uri,
		'type':'GET',
		'data':'pid='+pid,
		error: function(request) {
			$('#'+id).html('<option value="0">没有更多分类</option>');
        },
		success: function(data){
			if(data.status == 'success'){
				var result = data.data;
				var options ="";
				var firstid;
                if(result.length > 0){
                    $.each(result,function(k,e){
                    	if(k==0) firstid=e.area_id;
                        options +='<option value="'+e.area_id+'">'+e.title+'</option>';
                    });
                    if(id == 'city'){
                    	childAreas(firstid,uri,'area');
                    }
                    $('#'+id).html(options);
                }else{
    				$('#'+id).html('<option value="0">没有更多分类</option>');
    			}
			}else{
				$('#'+id).html('<option value="0">没有更多分类</option>');
			}
		},
	});
}
/**
 * 
 */
function toNextStep(){
	$("#step1").hide();
	$("#step2").show();
}
/**
 * 查看用户简历
 */
function viewResume(url)
{
	$.ajax({
		'url':url,
		'type':'GET',
		error:function(data){
			layer.open({title:'系统提示',content:'网络异常！'});
		},
		success:function(data){
			if(data.status=='success'){
				var result = data.data;
				var html='';
				var experiences='';
				var educationals= '';
				var projects='';
				$.each(result.resume.experiences,function(key,exp){
					experiences +=  ' <div class="resume-content mr_w840" id="experience">'
				                 +'     <div class="list_show" id="list_show_experience" >'
				                 +'         <div class="mr_jobe_list">'
				                 +'             <div class="clearfix">'
				                 +'                 <div class="mr_content_l">'
				                 +' 					<div class="l2">'
				                 +' 						<a class="projectTitle nourl">'+exp.company_name+'</a>'
				                 +' 						<p>'+exp.job+'</p>'
				                 +' 					</div>'
				                 +' 				</div>'
				                 +' 				<div class="mr_content_r">'
				                 +' 					<span>'+exp.start_at+' - '+exp.end_at+'</span>'
				                 +' 				</div>'
				                 +'             </div>'
				                 +'             <div class="mr_content_m">'
				                 +				exp.content
				                 +' 			</div>'
				                 +'         </div>'
				                 +'     </div>'
				                 +' </div>';
				});
				$.each(result.resume.educationals,function(ke,edu){
					educationals +=' <div class="resume-content mr_w840">'
				                 +'     <div class="list_show" id="list_show_educational" >'
				                 +'         <div class="mr_jobe_list">'
				                 +'             <div class="clearfix">'
				                 +'                 <div class="mr_content_l">'
				                 +' 					<div class="l2">'
				                 +' 						<a class="projectTitle nourl">'+edu.school+'</a>'
				                 +' 						<p>'+result.degrees[edu.degree]+'· '+edu.major+'</p>'
				                 +' 					</div>'
				                 +' 				</div>'
				                 +' 				<div class="mr_content_r">'
				                 +' 					<span>'+edu.graduated_at+'年毕业</span>'
				                 +'  				</div>'
				                 +'             </div>'
				                 +'         </div>'
				                 +'     </div>'
				                 +' </div>';
				});
				$.each(result.resume.projects,function(k,prj){
					projects += '<div class="mr_jobe_list">'
			                 +'              <div class="clearfix">'
			                 +'                 <div class="mr_content_l">'
			                 +' 					<div class="l2">'
			                 +' 						<a class="projectTitle nourl">'+prj.name+'</a>'
			                 +' 						<p>'+prj.duty+'</p>'
			                 +' 					</div>'
			                 +' 				</div>'
			                 +' 				<div class="mr_content_r">'
			                 +' 					<span>'+prj.start_at+' - '+prj.end_at+'</span>'
			                 +' 				</div>'
			                 +'             </div>'
			                 +' 			<div class="mr_content_m">'
			                 +				prj.intro
			                 +' 			</div>'
			                 +'         </div>';
				})
				var signature = '';
				if(result.resume.signature != null && result.resume.signature != undefined  )
					signature = result.resume.signature
				html='<div class="resume-header">'
	                 +'   	<img src="/images/front/member/bg.jpg">'
	                 +'       <div class="resume-header-logo">'
	                 +'           <img src="'+result.logo+'">'
	                 +'     </div>'
	                 +' </div>'
	                 +' <div class="resume-userinfo">'
	                 +'     <div class="resume-userinfo-title mr_w840 mb-15">'
	                 +'         <span  class="userinfo-show user-name">'+result.resume.real_name+'</span>'
	                 +'     </div>'
	                 +'     <div class="resume-userinfo-center mr_w840 mb-15">'
	                 +'         <span  class="userinfo-show">'+signature+'</span>'
	                 +'     </div>'
	                 +'     <div class="resume-userinfo-center mr_w840">'
	                 +'         <div class="mb-10">'
	                 +'             <span  class="userinfo-show">'
	                 +'                 <img src="/images/front/member/home.jpg">'
	                 +'                  <span class="ml-10">'+result.resume.shenfen+'</span>'
	                 +'              </span>'
	                 +'          </div>'
	                 +'          <div class="mb-10">'
	                 +'             <span  class="userinfo-show">'
	                 +'                 <img src="/images/front/member/data.jpg">'
	                 +'                 <span class="ml-10">'
	                 +'                     '+result.sex+'&nbsp;&nbsp;'
	                 +'                     '+result.age+'岁&nbsp;&nbsp;'
	                 +'                     '+result.degrees[result.degree]+'&nbsp;&nbsp;'
	                 +                     	result.gznxs[result.gznx]
	                 +'                 </span>'
	                 +'             </span>'
	                 +'         </div>'
	                 +'         <div class="mb-10">'
	                 +'             <span  class="userinfo-show">'
	                 +'                 <img src="/images/front/member/call.jpg">'
	                 +'                 <span class="ml-10">'
	                 +'                     '+result.resume.phone+'&nbsp;&nbsp;&nbsp;&nbsp;'
	                 +'                     <i class="icon-envelope"></i>&nbsp;'+result.resume.email
	                 +'                 </span>'
	                 +'             </span>'
	                 +'         </div>'
	                 +'     </div>' 
	                 +' </div>'
	                 +' <div class="mr_moudle_head clearfix mr_w840">'
	                 +' 	<div class="fl">'
	                 +' 		<div class="mr_title">'
	                 +' 			<span class="mr_title_l"></span><span class="mr_title_c">工作经历</span><span class="mr_title_r" style="width: 342px"></span>'
	                 +' 		</div>'
	                 +' 	</div>'
	                 +' </div>'
	                 +	experiences
	                 +' <div class="mr_moudle_head clearfix mr_w840">'
	                 +' 	<div class="fl">'
	                 +' 		<div class="mr_title">'
	                 +' 			<span class="mr_title_l"></span><span class="mr_title_c">教育经历</span><span class="mr_title_r" style="width: 342px"></span>'
	                 +' 		</div>'
	                 +' 	</div>'
	                 +' </div>'
	                 + educationals
	                 +' <div class="mr_moudle_head clearfix mr_w840">'
	                 +' 	<div class="fl">'
	                 +' 		<div class="mr_title">'
	                 +' 			<span class="mr_title_l"></span><span class="mr_title_c">项目经验</span><span class="mr_title_r" style="width: 342px"></span>'
	                 +' 		</div>'
	                 +' 	</div>'
	                 +' </div>'
	                 +' <div class="resume-content mr_w840">'
	                 +'     <div class="list_show" id="list_show_projects" >'
	                 +		projects
	                 +'     </div>'
	                 +' </div>'
	                 +' <div class="mr_moudle_head clearfix mr_w840">'
	                 +' 	<div class="fl">'
	                 +' 		<div class="mr_title">'
	                 +' 			<span class="mr_title_l"></span><span class="mr_title_c">自我描述</span><span class="mr_title_r" style="width: 342px"></span>'
	                 +' 		</div>'
	                 +' 	</div>'
	                 +' </div>'
	                 +' <div class="resume-content mr_w840">'
	                 +'    <div class="self_intro clearfix" id="intro_show">'
	                 +'     	<div class="fl self-intro-left">'
	                 +'     	   <img src="'+result.logo+'" width="80" height="80">'
	                 +'     	</div>	'
	                 +'     	<div class="fl self-intro-right" id="other_insert">'
	                 +			result.resume.otherinfo.intro
	                 +'         </div>'	
	                 +'     </div>'
	                 +' </div>'
	                 +' <div class="mr_moudle_head clearfix mr_w840">'
	                 +' 	<div class="fl">'
	                 +' 		<div class="mr_title">'
	                 +' 			<span class="mr_title_l"></span><span class="mr_title_c">期望工作</span><span class="mr_title_r" style="width: 342px"></span>'
	                 +' 		</div>'
	                 +' 	</div>'
	                 +' </div>';
	                 if(result.resume.otherinfo != 'undefined' && result.resume.otherinfo != null ){
		                 html+=' <div class="resume-content mr_w840">'
			                 +'     <div class="list_show" >'
			                 +'         <div class="mr_jobe_list clearfix" id="expect_show">'
			                 +'         	<ul>'
			                 +'         	   <li><i class="icon-user-md"></i>&nbsp;&nbsp;'+result.resume.otherinfo.expect_job+'</li>'
			                 +'         	   <li><i class="icon-time"></i>&nbsp;&nbsp;'+result.gzxzs[result.resume.otherinfo.job_type]+'</li>'
			                 +'         	   <li><i class="icon-map-marker"></i>&nbsp;&nbsp;'+result.resume.otherinfo.cityname+'</li>'
			                 +'         	   <li><i class="icon-money"></i>&nbsp;&nbsp;'+result.salarys[result.resume.otherinfo.expect_wages]+'</li>'
			                 +'         	</ul>'
			                 +'     	</div>'
			                 +' 	</div>'
			                 +'</div>';
	                 }
	                 html+= '<div class="mr_self_state company-center-form">'
		                 +'	<div class="form_wrap">'
		                 +'    <input id="resume_status" name="resume_status" type="button" class="form-control"  value="'+result.resume_status+'">'	                 						   	 				
		                 +'	</div>					'
		                 +'</div>';
	            var notify  = "changeResumeStatus2('"+result.url+"','"+result.token+"',2)";
	            var passed  = "changeResumeStatus2('"+result.url+"','"+result.token+"',3)";
	            var nopassed  = "changeResumeStatus2('"+result.url+"','"+result.token+"',1)";
				$('#myModalLabel').html(result.resume.real_name+'的简历');
				$('#resume_container').html(html);
				if(result.status == 2){
	            	$('#passed').removeClass('btn-action').addClass("btn-default")
	            	$('#nopassed').removeClass('btn-action').addClass("btn-default")
	            	$('#notify').removeClass('btn-default').addClass("btn-action");
	            	$('#passed').attr('onclick',passed);
					$('#nopassed').attr('onclick',nopassed);
	            }else if(result.status == 3){
	            	$('#notify').removeClass('btn-action').addClass("btn-default")
	            	$('#nopassed').removeClass('btn-action').addClass("btn-default")
	            	$('#passed').removeClass('btn-default').addClass("btn-action");
	            	$('#notify').attr('onclick',notify);
					$('#nopassed').attr('onclick',nopassed);
	            }else if(result.status == 1){
	            	$('#notify').removeClass('btn-action').addClass("btn-default")
	            	$('#passed').removeClass('btn-action').addClass("btn-default")
	            	$('#nopassed').removeClass('btn-default').addClass("btn-action");
	            	$('#notify').attr('onclick',notify);
					$('#passed').attr('onclick',passed);
	            }
				$('#myModal').modal();
			}else{
				layer.open({title:'系统提示',content:data.msg});
			}
		}
	});
}
/**
 * 企业对简历进行评论
 */
function resumeComment(url,modalid,formid,id)
{
	var data = $("#"+formid).serialize();
	$.ajax({
		'url':url,
		'type':'POST',
		'data':data,
		error: function(data) {
			var response = data.responseJSON;
			$.each(response,function(k,v){
				errors +="<div>"+v+"</div>";
			})
			layer.open({title:'错误提示',content:errors});
        },
        success: function(data){
        	if(data.status == 'success'){
        		$("#"+id).find("#dropdownMenu1").attr("data-toggle","");
        		$("#"+id).find("#dropdownMenu1").addClass("color-1"),
        		$("#"+id).find("#dropdownMenu1").html("企业已评");
        		$('#'+modalid).modal('hide');
        		layer.msg(data.msg);
        	}else{
        		layer.msg(data.msg);
        	}
        },
	});
}

/**
 * 消息详情
 */
function messageDetail(url,id)
{
    $.ajax({
        'url':url,
        'type':'GET',
        error: function(data) {
            layer.open({title:'提示',content:'网络异常'});
        },
        success: function(data){
            if(data.status == 'success')
            {
                var result = data.data;
                var html = "";
                $.each(result.data,function(k,v){
                    html += '<div class="talk_time">'+v.created_at+'</div>';
                    if(v.user_id != result.uid){
                        html += '<div class="ml-10 fl">'
                            +'<img src="'+result.otherLogo+'" width="50" height="50" style="border-radius: 25px;width: 50px; height: 50px;">'
                            +'<i class="glyphicon glyphicon-triangle-left" style="color:rgb(246,246,246);top:3px;left: -2px"></i>'
                            +'<div class="talk_left_d word">'
                            +'	<span class="talk_left_s">'+v.message+'</span>'
                            +'</div>'
                            +'</div><div class="clearfix"></div>';
                    }else{
                        html += '<div class="mr-10 fr">'
                            +'<img src="'+result.selfLogo+'" width="50" height="50" style="border-radius: 25px;width: 50px; height: 50px;" class="fr">'
                            +'<i class="glyphicon glyphicon-triangle-right" style="color:rgb(246,246,246);top: 20px;left: 105px;"></i>'
                            +'<div class="talk_right_d word">'
                            +'	<span class="talk_right_s">'+v.message+'</span>'
                            +'</div>'
                            +'</div><div class="clearfix"></div>';
                    }
                });
                html +="<input type='hidden' name='rid' value='"+result.rid+"'><input type='hidden' name='id' value='"+result.id+"'>";
                $('#myModalLabel').html(result.recipientname);
                $('#messge_send').attr('onclick','sendMessage("/company/center/message","messageForm")');
                $('#message_content').html(html);
                $('#myMessageDetail').modal();
                $('#unread_'+id).html(0);
            }
        }
    });
}
/**
 * 发送消息
 */
function sendMessage(url,formid)
{
    var data = $('#'+formid).serialize();
	console.log(url);
    $.ajax({
        'url':url,
        'type':'POST',
        'data':data,
        error: function(data) {
            layer.open({title:'提示',content:'网络异常'});
        },
        success: function(data){
            if(data.status == 'success'){
                var result = data.data;
                var html = '<div class="talk_time">'+result.created_at+'</div>';
                html += '<div class="mr-10 fr">'
                    +'<img src="'+result.selfLogo+'" width="50" height="50" style="border-radius: 25px;width: 50px; height: 50px;" class="fr">'
                    +'<i class="glyphicon glyphicon-triangle-right" style="color:rgb(246,246,246);top: 20px;left: 105px;"></i>'
                    +'<div class="talk_right_d word">'
                    +'	<span class="talk_right_s">'+result.message+'</span>'
                    +'</div>'
                    +'</div><div class="clearfix"></div>';
                $("#message_content").append(html);
                $("#msgContent").val('');
            }
            else
            {
                layer.open({title:'提示',content:data.msg});
            }
        }
    });
}